<?php

declare(strict_types=1);

namespace App\CustHub\Controller;

use App\Common\Helpers\CommonNotify;
use App\CustHub\Service\ChSeatService;
use App\CustHub\Service\RechargeService;
use Hyperf\HttpServer\Annotation\Controller;
use Hyperf\HttpServer\Annotation\RequestMapping;
use Yansongda\Artful\Exception\ContainerException;
use Yansongda\Artful\Exception\InvalidParamsException;

#[Controller('pay/notify')]
class PayNotifyController extends BaseController
{
    /**
     * 购买席位
     * @return \Psr\Http\Message\ResponseInterface|null
     * @throws \Psr\Container\ContainerExceptionInterface
     * @throws \Psr\Container\NotFoundExceptionInterface
     */
    #[RequestMapping('buySeatNotify')]
    public function buySeatNotify(): ?\Psr\Http\Message\ResponseInterface
    {
        $data = $this->request->all();
        return container()->get(CommonNotify::class)->notify($data,function ($outTradeNo, $transactionId, $ext){
            $result = container()->get(ChSeatService::class)->buySeatNotify($outTradeNo,$transactionId,$ext);
            return $result;
        });
    }

    /**
     * 席位续费
     * @throws \Psr\Container\ContainerExceptionInterface
     * @throws \Psr\Container\NotFoundExceptionInterface
     */
    #[RequestMapping('renewalSeatNotify')]
    public function renewalSeatNotify(): ?\Psr\Http\Message\ResponseInterface
    {
        return container()->get(CommonNotify::class)->notify($this->request->all(),function ($outTradeNo, $transactionId, $ext){
            $result = container()->get(ChSeatService::class)->renewalSeatNotify($outTradeNo,$transactionId,$ext);
            return $result;
        });
    }


    /**
     * 充值回调
     * @throws \Psr\Container\ContainerExceptionInterface
     * @throws \Psr\Container\NotFoundExceptionInterface
     */
    #[RequestMapping('rechargeNotify')]
    public function rechargeNotify(): ?\Psr\Http\Message\ResponseInterface
    {
        return container()->get(CommonNotify::class)->notify($this->request->all(),function ($outTradeNo, $transactionId, $ext){
            $result = container()->get(RechargeService::class)->rechargeNotify($outTradeNo,$transactionId,$ext);
            return $result;
        });
    }
}